package com.xxtx.trade.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.ArrayList;
import java.util.Collections;

@Configuration("admimWebConfig")
@Primary
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInterceptor()).addPathPatterns("/api/**").excludePathPatterns(getExcludeCommonPathPatterns().toArray(new String[]{}));
        super.addInterceptors(registry);
    }


    private ArrayList<String> getExcludeCommonPathPatterns() {
        ArrayList<String> list = new ArrayList<>();
        String[] urls = {
                "/api/v1/xxtx/sysUser/login",
                "/swagger-resources/**",
                "webjars/**/**",
                "/api/v2/xxtx/get/token",
                "/api/v2/xxtx/sim/send/msg",
                "/api/v2/xxtx/get/cmcc/token",
                "/api/v2/xxtx/sim/info/huazhi",
                "/api/v2/xxtx/sim/info/huazhi/state",
                "/api/v2/xxtx/warn/phone",
                "swagger-ui.html/**/**",
                "/api/v1/xxtx/wx/**",
                "/api/v1/xxtx/excel/**"
        };
        Collections.addAll(list, urls);
        return list;
    }
}
